package com.ghost.view.tip
{
	import com.ghost.UI.Ghost_tip_base;
	import com.ghost.UI.Ghost_txt;
	import com.ghost.manager.Source_manager;
	import com.ghost.manager.System_set;
	import com.ghost.model.Configure_url;
	import com.ghost.model.Global_data;
	import com.ghost.model.Object_pool;
	import com.ghost.model.UI_skin_data;
	import com.ghost.utils.MovieClipUtil;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.filters.GlowFilter;
	import flash.net.URLRequest;
	import flash.text.TextFieldAutoSize;
	import flash.utils.setTimeout;

	/**
	 * 提供装备tip
	 * @author ghost
	 */	
	public class Tip1 extends Ghost_tip_base
	{
		private var txt:Ghost_txt;
		private var bg:DisplayObject;
		private var ld:Loader;
		private var color_n:int;
		private var source_xml:String;
		private var id:String;
		private var wave_s:Sprite;//动画容器
		
		public function Tip1()
		{
			super();
			bg = new UI_skin_data.ghost_tip_skin_v[1]() as DisplayObject;
			this.addChild(bg);
			bg.width = 100;
			wave_s = new Sprite();
			this.addChild(wave_s);
			wave_s.y = 5;
			txt = new Ghost_txt();
			txt.scroll_bool = false;
			txt.txtwidth = bg.width;
			this.addChild(txt);
			txt.wordWrap = true;
			txt.multiline = true;
			txt.autoSize = TextFieldAutoSize.LEFT;
		}
		override public function show(id1:String,source_xml1:String,color_n1:int=0):void
		{
			color_n = color_n1;
			source_xml = source_xml1;
			id = id1;
			//根据需求修改-------------------------
			if(id=="0")this.visible=false;
			else
			{
				if(Object_pool.data_obj_pool.containsKey(source_xml))
				{
					this.visible=true;
					real_show();
				}
				else this.visible=false;
			}
		}
		private function real_show():void
		{
			trace(id,Object_pool.loaded_obj_pool.containsKey(id))
			if(Object_pool.loaded_obj_pool.containsKey(id))view();
			else
			{
				Object_pool.loaded_obj_pool.put(id,"");
				if(!ld)ld = new Loader();
				ld.unload();
				ld.load(new URLRequest(Configure_url.swf_url+"equipment/"+id+".swf"),System_set.getInstance().cn);
				ld.contentLoaderInfo.addEventListener(Event.COMPLETE,cHandler);
				ld.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,io_cHandler);
			}
		}
		private function io_cHandler(e:IOErrorEvent):void
		{
			Global_data.show_game_des.show(ld.loaderInfo.url+"is not found!");
		}
		private function cHandler(e:Event):void
		{
			ld.contentLoaderInfo.removeEventListener(Event.COMPLETE,cHandler);
			Object_pool.loaded_obj_pool.put(id,Source_manager.getInstance().getSource_c('move_'+id));
			//wave_s.addChild(ld);
			view();
		}
		private function view():void
		{
			if(Object_pool.loaded_obj_pool.get(id) != "" && Object_pool.loaded_obj_pool.get(id) != null)
			{
				MovieClipUtil.removeAllChild(wave_s);
				var cl:Class = Object_pool.loaded_obj_pool.get(id);
				wave_s.addChild(new cl());
				wave_s.x = bg.width/2-wave_s.width/2;
				txt.y = wave_s.height+wave_s.y;
				txt.htmlText = "<font size='16' color='"+color_v[color_n]+"'>"+Object_pool.data_obj_pool.get(source_xml).list[id].name+"</font><br>"+Object_pool.data_obj_pool.get(source_xml).list[id].des;
				set_bg_size();
			}
			else
			{
				setTimeout(view,100);
			}
		}
		private function set_bg_size():void
		{
			//bg.width = th.width;
			bg.height = this.height;
			bg.alpha = 0.6;
		}
		override public function set_bg(bg_class_v:Vector.<Object>):void
		{
			this.removeChild(bg);
			bg = null;
			bg = new bg_class_v[1]() as Bitmap;
			this.addChildAt(bg,0);
			set_bg_size();
		}
	}
}